<% add_decidim_meta_tags(
  description: translated_attribute(current_initiative.description),
  title: translated_attribute(current_initiative.title),
  url: initiative_url(current_initiative.id, locale: current_locale),
  resource: current_initiative) %>

<%
edit_link(
  resource_locator(current_participatory_space).edit,
  :read,
  :initiative
)
%>

<%= content_for :aside do %>
  <section class="initiative__aside">
    <% if current_initiative.published? || current_initiative.rejected? || current_initiative.accepted? || current_initiative.discarded? %>
      <% if current_initiative.votes_enabled? %>
        <section class="layout-aside__section layout-aside__buttons" id="initiative-<%= current_initiative.id %>-vote-cabin">
          <%= render partial: "vote_cabin", locals: { initiative: current_initiative } %>
        </section>
      <% end %>
    <% else %>
      <% if allowed_to?(:edit, :initiative, initiative: current_initiative) || allowed_to?(:send_to_technical_validation, :initiative, initiative: current_initiative) %>
        <section class="layout-aside__section layout-aside__buttons">
          <% if allowed_to? :edit, :initiative, initiative: current_initiative %>
            <%= link_to t(".edit"),
                        edit_initiative_path(current_initiative, locale: current_locale),
                        class: "button button__xl w-full button__secondary" %>
          <% end %>

          <% if allowed_to? :send_to_technical_validation, :initiative, initiative: current_initiative %>
            <%= link_to t(".send_to_technical_validation"),
                        send_to_technical_validation_initiative_path(current_initiative, locale: current_locale),
                        class: "button button__xl w-full button__secondary mt-4",
                        data: { confirm: t(".confirm") } %>
          <% end %>
        </section>
      <% end %>
    <% end %>

    <% unless current_initiative.validating? %>
      <section class="layout-aside__section">
        <%= render partial: "progress_bar" %>
      </section>
    <% end %>

    <section class="layout-aside__section">
      <%= cell("decidim/nav_links", initiative_nav_items(current_initiative)) %>
    </section>

    <% if current_initiative.type.promoting_committee_enabled? && current_user&.admin? %>
      <div class="layout-aside__section">
        <div class="initiative__aside__element__committee">
          <%= icon "account-circle-line", class: "fill-gray inline-block" %>
          <span class="ml-2 initiative__aside__element-title">
            <%= t("title", scope: "decidim.initiatives.admin.committee_requests.index") %>
          </span>
          <div class="ml-auto fill-secondary inline-block">
            <input id="urlShareLink-committee" type="text" class="!hidden" value="<%= decidim_initiatives.new_initiative_committee_request_url(current_initiative, locale: current_locale) %>" readonly>
            <button type="button" class="button button__sm button__text-secondary" data-controller="clipboard-copy" data-clipboard-copy="#urlShareLink-committee">
              <%= render_committee_tooltip %>
              <span class="sr-only"><%= t("decidim.shared.share_modal.copy_share_link") %></span>
            </button>
          </div>
        </div>
          <% if current_initiative.committee_members.empty? %>
            <span class="initiative__aside__element__data-text">
              <%= t("no_members_yet", scope: "decidim.initiatives.admin.committee_requests.index") %>
            </span>
          <% end %>
          <% current_initiative.committee_members.each do |request| %>
            <div class="author" data-id="<%= request.id %>">
              <div class="profile__group__list">
                <%= card_for request.user %>
              </div>
            </div>
          <% end %>
      </div>
    <% end %>

    <section class="layout-aside__section">
      <div class="mb-6">
        <%= icon "apps-line", class: "fill-gray inline-block" %>
        <span class="initiative__aside__element-title">
          <%= t("initiative_data", scope: "decidim.initiatives.initiatives.show") %>
        </span>
      </div>

      <div class="initiative__aside__element__data">
        <p class="initiative__aside__element__data-title">
          <%= t("state", scope: "decidim.initiatives.initiatives.show") %>
        </p>
        <span class="initiative__aside__element__data-text">
          <%= render partial: "initiative_badge", locals: { initiative: current_initiative } %>
        </span>
      </div>

      <% if current_initiative.offline_signature_type? || current_initiative.online_signature_type? %>
        <div class="initiative__aside__element__data">
          <p class="initiative__aside__element__data-title">
          <%= t("signature_collection", scope: "decidim.initiatives.initiatives.show") %>
          </p>
          <span class="initiative__aside__element__data-text">
            <span class="text-sm font-normal text-gray-2 block">
              <% if current_initiative.offline_signature_type? %>
                <%= t("offline", scope: "activemodel.attributes.initiative.signature_type_values") %>
              <% end %>
              <% if current_initiative.online_signature_type? %>
                <%= t("online", scope: "activemodel.attributes.initiative.signature_type_values") %>
              <% end %>
            </span>
          </span>
        </div>
      <% end %>

      <div class="initiative__aside__element__data">
        <p class="initiative__aside__element__data-title">
          <%= t("scope", scope: "decidim.initiatives.initiatives.show") %>
        </p>
        <span class="initiative__aside__element__data-text">
          <span class="text-sm font-normal text-gray-2 block">
            <%= link_to translated_attribute(current_initiative.scope_name), initiatives_path(filter: { with_any_scope: [current_initiative.scope&.id] }) %>
          </span>
        </span>
      </div>

      <div class="initiative__aside__element__data">
        <p class="initiative__aside__element__data-title">
          <%= t("type", scope: "decidim.initiatives.initiatives.show") %>
        </p>
        <span class="initiative__aside__element__data-text text-gray-2">
          <%= render partial: "tags_type", locals: { resource: current_initiative } %>
        </span>
      </div>

      <% if current_initiative.area %>
        <div class="initiative__aside__element__data">
          <p class="initiative__aside__element__data-title">
            <%= t("area", scope: "decidim.initiatives.initiatives.show") %>
          </p>
          <span class="initiative__aside__element__data-text">
            <span class="text-sm font-normal text-gray-2 block">
              <%= link_to translated_attribute(current_initiative.area_name), initiatives_path(filter: { with_any_area: [current_initiative.area.id] }) %>
            </span>
          </span>
        </div>
      <% end %>
    </section>
  </section>
<% end %>

<%= participatory_space_floating_help %>

<% if current_initiative.created? %>
  <% if allowed_to? :send_to_technical_validation, :initiative, initiative: current_initiative %>
    <%= cell("decidim/announcement", t(".send_to_technical_validation_announcement"), callout_class: "success") %>
  <% else %>
    <%= cell("decidim/announcement", t(".before_send_to_technical_validation_announcement",
                                       count: current_initiative.missing_committee_members,
                                       href: link_to(new_initiative_committee_request_url(current_initiative, locale: current_locale),
                                                     new_initiative_committee_request_path(current_initiative, locale: current_locale))), callout_class: "warning") %>
  <% end %>
<% end %>

<% add_decidim_page_title(translated_attribute(current_initiative.title)) %>

<section class="layout-main__section layout-main__heading">
  <h2 class="h2 decorator">
    <%= translated_attribute(current_initiative.title) %>
  </h2>
</section>

<section class="layout-main__section">
  <div class="content-block__description">
    <div class="editor-content">
      <%= decidim_sanitize_editor translated_attribute(current_initiative.description) %>
    </div>
  </div>
</section>

<section class="layout-main__section">
  <% if tabs.any? %>
    <div class="mt-8" data-controller="accordion" data-multiselectable="false" data-collapsible="false">
      <ul class="tab-x-container">
        <% tabs.each_with_index do |tab, i| %>
          <li>
            <button id="trigger-<%= tab[:id] %>" class="tab-x" data-controls="panel-<%= tab[:id] %>" data-open="<%= "true" if i.zero? %>">
              <%= icon tab[:icon], class: "text-gray fill-current" %><%= tab[:text] %>
            </button>
          </li>
        <% end %>
      </ul>

      <% panels.each do |panel| %>
        <div id="panel-<%= panel[:id] %>" class="py-8">
          <%= send(panel[:method], *panel[:args]) %>
        </div>
      <% end %>
    </div>
  <% end %>
</section>

<section class="layout-main__section">
  <%= render partial: "result", locals: { initiative: current_initiative } %>
</section>

<section class="layout-main__section layout-main__buttons" data-buttons>
  <% if current_initiative.commentable? && current_initiative.published? %>
    <%= cell "decidim/comments_button", nil, display: current_initiative.commentable? && current_initiative.published? %>
  <% end %>
  <div class="ml-auto lg:ml-0">
    <%= cell "decidim/share_widget", current_initiative %>
  </div>
</section>

<section class="layout-main__section layout-item__aside--footer">
  <%= comments_for current_initiative if current_initiative.commentable? && current_initiative.published? %>
  <ul class="metadata__container layout-main__section" data-metadata-footer>
    <%= content_tag :li, resource_reference(current_initiative), class: "metadata__item" %>
    <%= content_tag :li, resource_version(current_initiative, versions_path: initiative_version_path(current_initiative, current_initiative.versions.count, locale: current_locale)), class: "metadata__item" %>
  </ul>
</section>
